In [1]:
import os, geopandas as gpd
In [2]:
departArg=gpd.read_file(os.path.join("dataPais","ARG_adm","ARG_adm1.shp"))
In [3]:
#primero hallamos que tipo de documento es, nos dirá que es un geopandas
type(departArg)
Out[3]:
geopandas.geodataframe.GeoDataFrame
In [4]:
#nos va a permitir saber las columnas y las filas
departArg.shape
Out[4]:
(24, 10)
In [5]:
#hallaremos el nombre de la columna
departArg.columns
Out[5]:
Index(['ID_0', 'ISO', 'NAME_0', 'ID_1', 'NAME_1', 'TYPE_1', 'ENGTYPE_1',
       'NL_NAME_1', 'VARNAME_1', 'geometry'],
      dtype='object')
In [6]:
#para visualizar cuales son los primeros datos
departArg.head()
Out[6]:
ID_0 ISO NAME_0 ID_1 NAME_1 TYPE_1 ENGTYPE_1 NL_NAME_1 VARNAME_1 geometry
0 12 ARG Argentina 1 Buenos Aires Provincia Province None Baires|Buenos Ayres MULTIPOLYGON (((-62.79792 -41.02708, -62.79863...
1 12 ARG Argentina 2 Córdoba Provincia Province None Cordova POLYGON ((-63.91583 -29.61752, -63.89259 -29.6...
2 12 ARG Argentina 3 Catamarca Provincia Province None None POLYGON ((-67.56227 -25.26014, -67.55945 -25.2...
3 12 ARG Argentina 4 Chaco Provincia Province None El Chaco|Presidente Juan Peron POLYGON ((-62.32162 -24.10896, -62.32147 -24.1...
4 12 ARG Argentina 5 Chubut Provincia Province None None MULTIPOLYGON (((-66.99986 -46.00014, -67.00014...
In [7]:
#debemos verificar que no tenga ningún valor perdido
departArg[departArg.isna().any(axis=1)]
Out[7]:
ID_0 ISO NAME_0 ID_1 NAME_1 TYPE_1 ENGTYPE_1 NL_NAME_1 VARNAME_1 geometry
0 12 ARG Argentina 1 Buenos Aires Provincia Province None Baires|Buenos Ayres MULTIPOLYGON (((-62.79792 -41.02708, -62.79863...
1 12 ARG Argentina 2 Córdoba Provincia Province None Cordova POLYGON ((-63.91583 -29.61752, -63.89259 -29.6...
2 12 ARG Argentina 3 Catamarca Provincia Province None None POLYGON ((-67.56227 -25.26014, -67.55945 -25.2...
3 12 ARG Argentina 4 Chaco Provincia Province None El Chaco|Presidente Juan Peron POLYGON ((-62.32162 -24.10896, -62.32147 -24.1...
4 12 ARG Argentina 5 Chubut Provincia Province None None MULTIPOLYGON (((-66.99986 -46.00014, -67.00014...
5 12 ARG Argentina 6 Ciudad de Buenos Aires Distrito Federal Federal District None BUENOS AIRES D.F.|Capital Federal|Distretto Fe... POLYGON ((-58.44724 -34.69322, -58.46166 -34.7...
6 12 ARG Argentina 7 Corrientes Provincia Province None None POLYGON ((-58.15142 -27.26892, -58.13648 -27.2...
7 12 ARG Argentina 8 Entre Ríos Provincia Province None Entre-Rios MULTIPOLYGON (((-58.40125 -33.97681, -58.40125...
8 12 ARG Argentina 9 Formosa Provincia Province None None POLYGON ((-62.28558 -22.51684, -62.28345 -22.5...
9 12 ARG Argentina 10 Jujuy Provincia Province None None POLYGON ((-66.22112 -21.77855, -66.15830 -21.8...
10 12 ARG Argentina 11 La Pampa Provincia Province None El Pampa|Eva Perón POLYGON ((-64.39301 -34.99815, -64.35408 -34.9...
11 12 ARG Argentina 12 La Rioja Provincia Province None None POLYGON ((-68.49928 -27.75599, -68.50748 -27.7...
12 12 ARG Argentina 13 Mendoza Provincia Province None None POLYGON ((-69.11756 -32.01378, -69.11699 -32.0...
13 12 ARG Argentina 14 Misiones Provincia Province None Missões POLYGON ((-54.11761 -25.54422, -54.12143 -25.5...
14 12 ARG Argentina 15 Neuquén Provincia Province None Neuquén POLYGON ((-70.39233 -36.17107, -70.39227 -36.1...
15 12 ARG Argentina 16 Río Negro Provincia Province None None MULTIPOLYGON (((-64.99986 -42.00014, -65.00014...
16 12 ARG Argentina 17 Salta Provincia Province None None POLYGON ((-63.78167 -22.00259, -63.76935 -22.0...
17 12 ARG Argentina 18 San Juan Provincia Province None None POLYGON ((-69.60582 -28.37947, -69.60296 -28.3...
18 12 ARG Argentina 19 San Luis Provincia Province None None POLYGON ((-67.24355 -31.88650, -67.23670 -31.8...
19 12 ARG Argentina 20 Santa Cruz Provincia Province None None MULTIPOLYGON (((-69.10917 -51.65569, -69.10917...
20 12 ARG Argentina 21 Santa Fe Provincia Province None Santa Fé POLYGON ((-61.71717 -27.99393, -61.66463 -27.9...
21 12 ARG Argentina 22 Santiago del Estero Provincia Province None None POLYGON ((-62.87748 -25.65497, -62.86933 -25.6...
22 12 ARG Argentina 23 Tierra del Fuego Territorio Nacional|Provincia National Territory None Feuerland|Terra del Fuoco|Terre de Feu|Terra d... MULTIPOLYGON (((-66.54916 -55.05958, -66.54916...
23 12 ARG Argentina 24 Tucumán Provincia Province None Tucumão POLYGON ((-65.33595 -26.07400, -65.32600 -26.0...
In [8]:
#averiguamos que tipo es
departArg.info()
<class 'geopandas.geodataframe.GeoDataFrame'>
RangeIndex: 24 entries, 0 to 23
Data columns (total 10 columns):
 #   Column     Non-Null Count  Dtype   
---  ------     --------------  -----   
 0   ID_0       24 non-null     int64   
 1   ISO        24 non-null     object  
 2   NAME_0     24 non-null     object  
 3   ID_1       24 non-null     int64   
 4   NAME_1     24 non-null     object  
 5   TYPE_1     24 non-null     object  
 6   ENGTYPE_1  24 non-null     object  
 7   NL_NAME_1  0 non-null      object  
 8   VARNAME_1  11 non-null     object  
 9   geometry   24 non-null     geometry
dtypes: geometry(1), int64(2), object(7)
memory usage: 2.0+ KB
In [9]:
# plot simple

departArg.plot()
Out[9]:
<AxesSubplot:>
In [10]:
#abrimos los dos mapas siguientes (las provincias y los ríos pertenecientes a Argentina)
riosArg=gpd.read_file(os.path.join("dataPais","ARG_wat","ARG_water_lines_dcw.shp"))
ciudadesArg=gpd.read_file(os.path.join("dataPais","ARG_adm","ARG_adm2.shp"))
In [11]:
#corroboramos que los datos pertenezcan a las ciudades de Argentina
ciudadesArg.head()
Out[11]:
ID_0 ISO NAME_0 ID_1 NAME_1 ID_2 NAME_2 TYPE_2 ENGTYPE_2 NL_NAME_2 VARNAME_2 geometry
0 12 ARG Argentina 1 Buenos Aires 1 Adolfo Alsina Partido Part None Carhue POLYGON ((-63.39251 -37.72096, -63.39250 -37.7...
1 12 ARG Argentina 1 Buenos Aires 2 Adolfo Gonzales Chaves Partido Part None Adolfo Gonzal POLYGON ((-60.68344 -38.09533, -60.76242 -38.0...
2 12 ARG Argentina 1 Buenos Aires 3 Alberti Partido Part None None POLYGON ((-60.32552 -35.23001, -60.32092 -35.2...
3 12 ARG Argentina 1 Buenos Aires 4 Almirante Brown Partido Part None None POLYGON ((-58.34326 -34.89314, -58.34735 -34.8...
4 12 ARG Argentina 1 Buenos Aires 5 Ameghino Partido Part None None POLYGON ((-62.08816 -34.97584, -62.18175 -35.0...
In [12]:
#primero visualizaremos las ciudades
ciudadesArg.plot()
Out[12]:
<AxesSubplot:>
In [13]:
#corroboramos que los datos pertenezcan a los ríos de Argentina
riosArg.head()
Out[13]:
F_CODE_DES HYC_DESCRI NAM ISO NAME_0 geometry
0 River/Stream Non-Perennial/Intermittent/Fluctuating UNK ARG Argentina LINESTRING (-62.95552 -22.01840, -62.95388 -22...
1 River/Stream Non-Perennial/Intermittent/Fluctuating UNK ARG Argentina LINESTRING (-62.95552 -22.01840, -62.96658 -22...
2 River/Stream Non-Perennial/Intermittent/Fluctuating RIO MUERTO ARG Argentina LINESTRING (-62.95552 -22.01840, -62.94953 -22...
3 River/Stream Perennial/Permanent RIO CINCEL ARG Argentina LINESTRING (-65.99427 -22.44915, -65.99702 -22...
4 River/Stream Non-Perennial/Intermittent/Fluctuating UNK ARG Argentina LINESTRING (-63.33389 -22.50236, -63.35136 -22...
In [14]:
#visualizamos los ríos 
riosArg.plot()
Out[14]:
<AxesSubplot:>
In [15]:
#le cambiamos las características visuales para que se aprecie mejor la provincia,las ciudades y los ríos
departArg.plot(facecolor="lightskyblue",
               edgecolor='darkslategrey', 
               linewidth=0.1) 
Out[15]:
<AxesSubplot:>
In [16]:
riosArg.plot(edgecolor='navy', 
            linewidth=0.4,
            linestyle='dashed')
Out[16]:
<AxesSubplot:>
In [17]:
ciudadesArg.plot(marker='3',
            color='skyblue', 
            markersize=1,
            alpha=1)
Out[17]:
<AxesSubplot:>
In [18]:
#ahora uniremos los 3 mapas en uno solo para ello debemos verificar que todos tengan el mismo nombre
departArg.crs
Out[18]:
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
In [19]:
ciudadesArg.crs
Out[19]:
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
In [20]:
riosArg.crs
Out[20]:
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
In [21]:
#ahora debemos poner capa por capa 
base = departArg.plot(facecolor="lightskyblue", edgecolor='darkslategrey', linewidth=1,figsize=(12,12))
ciudadesArg.plot(marker='6', color='honeydew', markersize=5,alpha=0.9,
            ax=base)
riosArg.plot(edgecolor='navy', linewidth=0.2,
            ax=base)
Out[21]:
<AxesSubplot:>
In [22]:
import folium
In [23]:
#para realizarlo de forma dinamica
m=ciudadesArg.explore(color="honeydew", 
                   name="ciudadesArg")

m=riosArg.explore(m=m, color="navy",
                   name="riosArg")
#folium.LayerControl().add_to(m)
m
Out[23]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [24]:
#ahora nos enfocamos en una provincia
Catamarca=departArg[departArg.NAME_1=='Catamarca']
In [25]:
#recortamos lo que no necesitamos
ciudadesArg_clipped = gpd.clip(gdf=ciudadesArg,
                          mask=Catamarca)
riosArg_clipped = gpd.clip(gdf=riosArg,
                               mask=Catamarca)
In [26]:
baseCiudad= Catamarca.plot(facecolor="black", edgecolor='navy', linewidth=0.7,figsize=(5,5))
ciudadesArg_clipped.plot(marker='+', color='lightskyblue', markersize=15,ax=baseCiudad)
riosArg_clipped.plot(edgecolor='blue', linewidth=0.5,ax=baseCiudad)
Out[26]:
<AxesSubplot:>
In [27]:
#ubicamos las coordenadas para que nos dirija de frente ahí
CatamarcaCoordenadas=[-28.46957,-65.78524]
In [28]:
m = Catamarca.explore(location=CatamarcaCoordenadas,
                   zoom_start=7,
                   tiles='CartoDB positron',
                   color='lightskyblue',
                   name="departArg")
m = riosArg_clipped.explore(m=m, color="navy",
                   name="riosArg")
#folium.LayerControl().add_to(m) 
m
Out[28]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [29]:
import matplotlib.pyplot as plt

baseCiudad= Catamarca.plot(facecolor="black", edgecolor='navy', linewidth=0.7,figsize=(5,5))
map2=ciudadesArg_clipped.plot(marker='+', color='lightskyblue', markersize=15,ax=baseCiudad)
mapEnd=riosArg_clipped.plot(edgecolor='navy', linewidth=0.5,ax=baseCiudad)
plt.savefig(os.path.join("dataPais",'mapEnd.jpg'))
In [31]:
#exportamos los datos
departArg.to_file(os.path.join("dataPais","MAPAS_FINALES.gpkg"), layer='departArg', driver="GPKG")
ciudadesArg.to_file(os.path.join("dataPais","MAPAS_FINALES.gpkg"), layer='ciudadArg', driver="GPKG")
riosArg.to_file(os.path.join("dataPais","MAPAS_FINALES.gpkg"), layer='riosArg', driver="GPKG")
In [32]:
mapaArgentina='https://github.com/GaliaGabrielaG/geodataPais_Provincia/raw/main/dataPais/MAPAS_FINALES.gpkg'
In [33]:
from  fiona import listlayers

listlayers(mapaArgentina)
Out[33]:
['departArg', 'ciudadArg', 'riosArg']
In [35]:
departArg=gpd.read_file(mapaArgentina,layer='departArg')
ciudadesArg=gpd.read_file(mapaArgentina,layer='ciudadArg')
riosArg=gpd.read_file(mapaArgentina,layer='riosArg')
In [39]:
baseCiudad = departArg.plot(facecolor='blue')
ciudadesArg.plot(ax=baseCiudad, markersize=0.5, color='lightskyblue') 
riosArg.plot(ax=baseCiudad, linewidth=0.5)
Out[39]:
<AxesSubplot:>
In [ ]: